myde_count=$this->numeric($myde_count); $this->myde_size=$this->numeric($myde_size); $this->myde_page=$this->numeric($myde_page); $this->page_limit=($this->myde_page * $this -> myde_size) - $this -> myde_size; //下一页的开始记录 $this->page_url=$page_url; //连接的地址 if($this->myde_page<1)$this->myde_page=1; //当前页小于1的时候,,值赋值为1 if($this->myde_count<0)$this->myde_page=0; $this->myde_page_count=ceil($this->myde_count/$this->myde_size);//总页数 if($this->myde_page_count<1) $this->myde_page_count=1; if($this->myde_page > $this->myde_page_count) $this->myde_page = $this->myde_page_count; //控制显示出来多少个页码(这个是原来的) //$this->page_i = $this->myde_page-2; //$this->page_ub = $this->myde_page+2; $this->page_i = $this->myde_page; $this->page_ub = $this->myde_page+5; //以下这个if语句是保证显示5个页码 if($this->page_ub > $this->myde_page_count) { $this->page_ub = $this->myde_page_count; $this->page_i = $this->page_ub-5; } if($this->page_i<1)$this->page_i=1; if($this->page_ub>$this->myde_page_count){$this->page_ub=$this->myde_page_count; } } private function numeric($id) //判断是否为数字 { if (strlen($id)) { if (!ereg("^[0-9]+$",$id)) $id = 1; } else { $id = 1; } return $id; } private function page_replace($page) //地址替换 {return str_replace("{page}", $page, $this -> page_url);} private function myde_home() //首页 { if($this -> myde_page != 1){ return " page_replace(1)."\" title=\"首页\" >首页\n"; }else{ return " 首页\n"; } } private function myde_prev() //上一页 { if($this -> myde_page != 1){ return " page_replace($this->myde_page-1) ."\" title=\"上一页\" >上一页\n"; }else{ return " 上一页\n"; } } private function myde_next() //下一页 { if($this -> myde_page != $this -> myde_page_count){ return " page_replace($this->myde_page+1) ."\" title=\"下一页\" >下一页\n"; }else { return " 下一页\n"; } } private function myde_last() //尾页 { if($this -> myde_page != $this -> myde_page_count){ return " page_replace($this -> myde_page_count)."\" title=\"尾页\" >尾页\n"; }else{ return " 尾页\n"; } } function myde_write($id='page') //输出 { $str = " \n"; $str .= "
总记录:".$this -> myde_count."\n"; $str .= "
".$this -> myde_page."/
".$this -> myde_page_count."\n"; $str .= $this -> myde_home(); //调用方法,显示“首页” $str .= $this -> myde_prev(); //调用方法,显示“上一页” //以下显示1,2,3...分页 for($page_for_i=$this->page_i;$page_for_i <= $this -> page_ub;$page_for_i++){ if($this -> myde_page == $page_for_i){ $str .= "
".$page_for_i."\n"; } else{ $str .= "
page_replace($page_for_i)."\" title=\"第".$page_for_i."页\">"; $str .= $page_for_i . "\n"; } } $str .= $this -> myde_next(); //调用方法,显示“下一页” $str .= $this -> myde_last(); //调用方法,显示“尾页” //以下是显示跳转页框 $str .= "
myde_page."\""; $str .= "οnmοuseοver=\"javascript:this.value='';this.focus();\" οnkeydοwn=\"javascript: if(event.keyCode==13){ location='"; $str .= $this -> page_replace("'+this.value+'")."';return false;}\""; $str .= " title=\"输入您想要到达的页码,然后回车!\" />\n"; //以上是显示跳转页框 $str .= "
"; return $str; } function myde_write1($id='page') //输出 { $str = " \n
\n "; $str .= "总记录:".$this -> myde_count."\n"; $str .= "".$this -> myde_page."/".$this -> myde_page_count."\n"; $str .= $this -> myde_home(); //调用方法,显示“首页” $str .= $this -> myde_prev(); //调用方法,显示“上一页” //以下显示1,2,3...分页 for($page_for_i=$this->page_i;$page_for_i <= $this->page_ub;$page_for_i++){ if($this -> myde_page == $page_for_i) { $str .= "".$page_for_i."\n"; } else{ $str .= " page_replace($page_for_i)."\" title=\"第".$page_for_i."页\">"; $str .= $page_for_i . "\n"; } //以上显示1,2,3...分页 } $str .= $this -> myde_next(); //调用方法,显示“下一页” $str .= $this -> myde_last(); //调用方法,显示“尾页” //以下是显示下拉式跳转页框 /*$str .="\n"; //以上是显示下拉式跳转页框 //以下是显示跳转页框 $str .= " myde_page."\""; $str .= "οnmοuseοver=\"javascript:this.value='';this.focus();\" οnkeydοwn=\"javascript: if(event.keyCode==13){ location='"; $str .= $this -> page_replace("'+this.value+'")."';return false;}\""; $str .= "title=\"输入您想要到达的页码,然后回车!\" />\n";*/ //以上是显示跳转页框 $str .= " "; return $str; } } /*-------------------------实例--------------------------------* $page = new PageClass(1000,5,$_GET['page'],'?page={page}');//用于动态 $page = new PageClass(1000,5,$_GET['page'],'list-{page}.html');//用于静态或者伪静态 $page -> myde_write();//显示 */ ?> /*******************调用*******************/
$page=$_GET['page']; // 第几页; $table='news'; $sql_n="SELECT id FROM ".$table; $query_n=mysql_query($sql_n); $totail=mysql_num_rows($query_n);//记录总条数 $number=8;//每页显示条数 $my_page=new PageClass($totail,$number,$page,'?page={page}');//参数设定:总记录,每页显示的条数,当前页,连接的地址 $sql="SELECT * FROM ".$table." order by riqi desc LIMIT ".$my_page->page_limit.",".$my_page->myde_size; $query=mysql_query($sql); while($data=mysql_fetch_assoc($query)){ $datas[]=$data; }